package Utils;

/*日期格式与字符串转换*/
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;
import java.util.Set;

public final class StringUtil {
    /*字符串转换为日期*/
    public static Date convertToDate(String content){
        Date date = null;
        try {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            date = sdf.parse(content);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return date;
    }

    //日期转换为字符串
    public static String convertToString(Date date){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return sdf.format(date);
    }
    //特殊字符转换
    public static String filter(String content,Map<String,String> map){
        Set<String> keys =  map.keySet();
        for(String key : keys){
            content = content.replaceAll(key, map.get(key));
        }
        return content;
    }
}
